package cn.jjxx.modules.sso.controller;

import java.io.IOException;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.expression.AccessException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.jjxx.core.model.AjaxJson;
import cn.jjxx.modules.sso.entity.TokenEntity;
import cn.jjxx.modules.sso.service.ISSOServerService;
import cn.jjxx.modules.sys.entity.User;

@Controller
@RequestMapping("${admin.url.prefix}/sso/server")
public class SSOServerController {
	
	@Autowired
	private ISSOServerService ssoServerService;

	@RequestMapping("checkLogin")
	public void checkLogin(TokenEntity tokenEntity,HttpServletRequest request,HttpServletResponse response) throws IOException{
		ssoServerService.checkLogin(tokenEntity, request, response);	
	}
	
	@ResponseBody
	@RequestMapping(value="/tokenCheck",method=RequestMethod.POST)
	public AjaxJson tokenCheck(TokenEntity token){
		return ssoServerService.tokenCheck(token);
	}
	
	@RequestMapping(value="/login",method=RequestMethod.POST)
	public void login(HttpServletRequest request,HttpServletResponse response,User user) throws IOException{
		ssoServerService.ssoLogin(user, request, response);
	}
	
	//登出
	@RequestMapping(value="/logout")
	public String logout(String redirectUrl,HttpServletRequest request,HttpServletResponse response,TokenEntity tokenEntity){
		ssoServerService.ssoLogout();
		return "redirect:"+redirectUrl;
	}
	
	
}
